package tep;

import java.util.HashMap;

public class ch2 {

    public int numberOfSubarrays(int[] nums, int k) {
        HashMap<Integer,Integer> map = new HashMap<>();
        map.put(0,1);
        int num = 0;
        int sum = 0;
        for(int i:nums){
            if(i%2==1){
                num++;
            }
            if(map.containsKey(num-k)){
                sum += map.get(num-k);
            }
            map.put(num,map.getOrDefault(num,0)+1);
        }
        return sum;

    }


    public int[] searchRange(int[] nums, int target) {
        if(nums.length==0){
            return new int[]{-1,-1};
        }

        int left = 0;
        int right = nums.length;

        //大于等于
        while (left<right){
            int mid = (left+right)/2;
            if(nums[mid]>=target){
                right = mid;
            }else {
                left = mid+1;
            }

        }
        int l = left;

        left = 0;
        right = nums.length;

        //严格大于
        while (left<right){
            int mid = (left+right)/2;
            if(nums[mid]<=target){
                left = mid+1;
            }else {
                right = mid;
            }
        }
        int r = left;


        if(l==0&&nums[l]==0){

        }

        if(nums[r-1]==target&&nums[l+1]==target){
            return new int[]{l+1,r-1};
        }

        return new int[]{-1,-1};




    }
}
